﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CPS1
{
    // NUDY: Patrz VaultSignal
    public class RectangularSignal : Signal
    {
        public Double kw; // współczynnik wypełnienia

        public RectangularSignal(Double A, Double T, Double t1, Double d, Double kw, Double f, String name) 
        {
            this.A = A;
            this.T = T;
            this.t1 = t1;
            this.d = d;
            this.kw = kw;
            this.f = f;
            this.name = name;
            this.periodical = true;
            this.discrete = false;

            int amount = (int) Math.Ceiling(d * f);
            this.calculatedValues = new Double[amount, 2];
        }

        override public Double value(Double t) 
        {
            // numer bieżącego okresu
            Double k = Math.Floor(t / T); 
            // wzorek z instrukcji
            if (t >= ((k * T) - t1)  && t < ((kw * T) + (k * T) - t1))
            {
                return this.A;
            }
            else
            {
                return 0;
            }
        }

        public override Signal copy()
        {
            RectangularSignal copied = new RectangularSignal(this.A, this.T, this.t1, this.d, this.kw, this.f, this.name);
            copied.calculateSignal();
            return copied;
        }
    }
}
